<template>
  <div class="head-title">
    <van-nav-bar left-text="返回" title="修改密码"  left-arrow fixed  @click-left="onClickLeft" />

        <!-- 用户名 -->
        <van-field v-model="oldPassword" type="text" label="旧密码" />
        <!-- 手机号 -->
        <van-field v-model="newPassword" type="text" label="新密码" />

        <van-field v-model="mobile_No" center clearable  placeholder="请输入手机号码">
          <template #button>
            <van-button size="small" type="primary" @click="sendSMS()">发送验证码</van-button>
          </template>
        </van-field>
        <van-field v-model="verif_code" center clearable  placeholder="请输入短信验证码"></van-field>

        <van-button type="primary" block  @click="ChangePassword()" class="btn">保存</van-button>
 
  </div>
</template>

<script>

export default {
  data() {
    return {
      id: null,//用户ID
      oldPassword: null,//"string",//旧密码
      newPassword: null,//"string",//新密码
      mobile_No: null,//"string",//手机号
      verif_code: null,//"string"//手机验证码
    };
  },
  methods: { 

    //修改密码
    ChangePassword() {
      const PWD = JSON.parse(sessionStorage.getItem("PWD"));
      this.$axios({
        method: "post",
        url: "/api/User/ChangePassword",
        headers: {sessionKey:PWD.sessionKey,authorization:PWD.token},
        data: {
            id: PWD.id,//用户ID
            oldPassword: this.oldPassword,//旧密码
            newPassword: this.newPassword,//新密码
            mobile_No: this.mobile_No,//手机号
            verif_code: this.verif_code//手机验证码
        }
      })
        .then(res => {
          if (res.data.code === 0) {
              this.$toast({
                duration: 800,
                message: res.data.Message
              });
          }
          if (res.data.code == 1) {
            this.$toast({
              duration: 800,
              message: res.data.Message
            });
          }
        })
        .catch(err => {
          console.log(err);
        });
    },
    //返回
    onClickLeft() {
      // this.$router.push("/home");
      this.$router.go(-1);
    }
    //以下为无效代码
  },
  //页面初始化钩子函数 created
  created() {

    // const PWD = JSON.parse(sessionStorage.getItem("PWD"));
    // this.id =  PWD.id,//用户ID

    this.$emit("header", false);
    this.$emit("footer", false);
  },
  //页面初始化钩子函数 mounted
  mounted() {
  }
};
</script>
<style lang="less" scoped>
  .btn{
      margin-top: 20px;
  }
</style>

